#!/usr/bin/env python
# -*- coding:utf8 -*-

"""
@version: 
@author: lh
@license: Apache Licence 
@contact: liuhuan0672@gmail.com
@site: 
@software: PyCharm
@file: 0015.py
@time: 2016/1/21 15:47

第 0015 题： 纯文本文件 city.txt为城市信息, 里面的内容（包括花括号）如下所示：
{
    "1" : "上海",
    "2" : "北京",
    "3" : "成都"
}
请将上述内容写到 city.xls 文件中.

"""
import json

import xlwt3


def write_txt_to_xls(txt_file):
    txt_file = open(txt_file, 'r', encoding="utf-8")
    file_context = json.load(txt_file)

    xls_obj = xlwt3.Workbook(encoding="utf-8")
    sheet = xls_obj.add_sheet('city')
    for i in range(len(file_context)):
        sheet.write(i, 0, i + 1)
        data = file_context[str(i + 1)]
        sheet.write(i, 1, data)
    xls_obj.save("./result/city.xls")


if __name__ == '__main__':
    write_txt_to_xls("./static/city.txt")
